package org.supsi.QRreader;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

import com.google.zxing.integration.*;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

public class MainActivity extends Activity {

    public final static String EXTRA_MAC = "org.supsi.QRreader.MAC";
    public final static String EXTRA_PIN = "org.supsi.QRreader.PIN";

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;

	}

	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
		if (scanResult != null) {
			
			String mac = scanResult.getContents().split(" ")[0];
			String pin = scanResult.getContents().split(" ")[1];
			Intent btIntent = new Intent(this, BTConnection.class);
			btIntent.putExtra(EXTRA_MAC, mac);
			btIntent.putExtra(EXTRA_PIN, pin);
			
			startActivity(btIntent);

		}
		// else continue with any other code you need in the method
		;
	}


	public void startScan(View view){
		IntentIntegrator integrator = new IntentIntegrator(this);
		integrator.initiateScan();
	}
}
